package com.ticket.sass.admin.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ticket.sass.admin.dto.input.cinema.CinemaListInput;
import com.ticket.sass.admin.mapper.CinemaMapper;
import com.ticket.sass.admin.service.BaseService;
import com.ticket.sass.common.entity.tenant.CinemaEntity;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 影院列表 服务实现类
 * </p>
 *
 * @author ywb
 * @since 2024-03-06
 */
@Service
public class CinemaServiceImpl extends ServiceImpl<CinemaMapper, CinemaEntity> implements BaseService<CinemaEntity> {
    public Long getTenantIdByCinemaId(Long cinemaId) {
        QueryWrapper<CinemaEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("tenant_id").eq("id", cinemaId);
        CinemaEntity cinemaEntity = this.getOne(queryWrapper);
        return cinemaEntity != null ? cinemaEntity.getTenantId() : null;
    }
    
    public IPage<CinemaEntity> iPage(CinemaListInput input) {
        Page<CinemaEntity> page = new Page<>(input.getPageNum(), input.getPageSize());
        QueryWrapper<CinemaEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        
        if (input.getName() != null && !input.getName().isEmpty()) {
            queryWrapper.lambda().like(CinemaEntity::getName, input.getName())
                .or().like(CinemaEntity::getShortName, input.getName())
                .or().like(CinemaEntity::getZzCode, input.getName());
        }
        
        return this.page(page, queryWrapper);
    }
}
